package com.eleventwelve.iris.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.opentides.util.StringUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.eleventwelve.iris.service.TreatmentService;

/**
 * 
 * @author Ashley
 *
 */
public class DeleteTreatmentController extends AbstractController{
	private TreatmentService treatmentService;
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		
		String id = request.getParameter("id");
		Long patientId = (long) 0;
		if(!StringUtil.isEmpty(id) && StringUtils.isNumeric(id)){
			patientId = treatmentService.load(id).getPatient().getId();
			treatmentService.delete(id);
		}
		
		return new ModelAndView("redirect:/patient.jspx?action=delete&item=Treatment&id="+patientId);
	}

	public TreatmentService getTreatmentService() {
		return treatmentService;
	}

	public void setTreatmentService(TreatmentService treatmentService) {
		this.treatmentService = treatmentService;
	}

}
